﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using Jc.MicroDesigner.Objects;

namespace Jc.MicroDesigner.Drawings.SpecialObjects
{
    /// <summary>
    /// Элемент "Область выделения"
    /// </summary>
    public class RegionObject : BaseElement
    {
        private class RegionImage : ElementImage
        {
            public RegionImage(RegionObject parent)
                : base(parent)
            {
                onPaint += new Jc.MicroDesigner.Events.onPaintElement(_DrawOptions_onPaint);
            }

            public override bool CheckSelection(int x, int y)
            {
                bool res = base.CheckSelection(x, y);
                if (res)
                {
                    res = (x <= _Left + 3) | (x >= _Left + _Width - 3) | (y <= _Top + 3) | (y >= _Top + _Height - 3);
                }
                return res;
            }

            void _DrawOptions_onPaint(System.Drawing.Image img, BaseElement element)
            {
                Graphics g = Graphics.FromImage(img);
                Pen dashed_pen = new Pen(Color.Navy);
                dashed_pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash;
                if ((Width > 4) && (Height > 4))
                    g.DrawRectangle(dashed_pen,
                        new Rectangle(0, 0, Width - 3, Height - 3));
            }
        }

        public RegionObject()
            : this("Region")   { }

        public RegionObject(string name) : base(name)
        {
            this._DrawOptions = new RegionImage(this);
        }
    }
}